const fs = require("fs")
const path = require("path")
const https = require('https');
 
https.get(`https://cpu.bmcx.com/web_system/bmcx_com_www/system/file/cpu/get_data/?lx=cpu&s=1&e=999999999&ajaxtimestamp=${new Date().getTime()}`, (resp) => {
 let data = '';
 resp.on('data', (chunk) => {
  data += chunk;
 });
 resp.on('end', () => {
    let jsonData = JSON.parse(data)
    let newJsonData = []
    jsonData.forEach(item => {
        newJsonData.push({
            name:item.ming_cheng,
            score:item.shu_zhi,
        })
    });
    fs.writeFileSync(path.resolve(__dirname,"../public/cpuData.json"),JSON.stringify(newJsonData));
//   console.log(JSON.parse(data));
 });
}).on("error", (err) => {
 console.log("Error: " + err.message);
});
